package com.haierp.controller;

import java.net.URLDecoder;
import java.util.Calendar;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.haierp.service.IOneHaoCangService;
import com.haierp.util.DateUtil;
import com.haierp.util.JsonResult;
import com.wangzhixuan.commons.base.BaseController;

/**
 * 1号仓同步
 * 
 * @author 刘洋
 *
 */
@Controller
@RequestMapping("/oneHaoCang")
public class OneHaoCangController extends BaseController {
	@Autowired
	IOneHaoCangService oneHaoCangService;
	
	/**
	 * 同步1号仓的商品
	 */
	@RequestMapping("/synItemList")
	@ResponseBody
	public Object synItemList() {
		try {
			//oneHaoCangService.synItemList();
			oneHaoCangService.synItemList("a4cb9854-d1f8-468c-a8bf-a75e00bb12ed");
			return JsonResult.buildSuccess("同步1号仓商品成功");
		} catch(Exception e) {
			return JsonResult.buildFailed("同步1号仓商品异常");
		}
		
	}
	
	/**
	 * 同步1号仓的库存
	 */
	@RequestMapping("/synItemInventory")
	@ResponseBody
	public Object synItemInventory() {
		try {
			oneHaoCangService.synItemInventory();
			return JsonResult.buildSuccess("同步1号仓库存成功");
		} catch(Exception e) {
			return JsonResult.buildFailed("同步1号仓库存异常");
		}
		
	}
	
	public static void main(String[] args) throws Exception {
		//主订单
		//System.out.println("P" + DateUtil.formatDate(new Date(), DateUtil.DATE_PARTEN_YYMMDDHHMMSS));
		//子订单
		System.out.println(String.format("%0"+4+"d", 5));
		
		System.out.println("P17052019203010000".substring(1));
		
		String tt = "<p><img src=\"http://haierp.oss-cn-hangzhou.aliyuncs.com/10_1495439795367.jpg\" alt=\"微信图片_20170522150902\" style=\"max-width:100%;\"></p><p><br></p>";
		String tt2 = URLDecoder.decode(tt, "UTF-8");
		System.out.println(tt2);
		
		Date date = new Date();
		System.out.println(DateUtil.getDateByCalculate(date, Calendar.DATE, 1));
	}
}
